/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.view;

import com.sdd.entities.Delivery;
import com.sdd.facades.business.DeliveryBusinessFacadeBean;
import com.sdd.facades.business.OrderBusinessFacadeBean;
import com.sdd.facades.factories.OrderFactoryFacadeBean;
import com.sdd.facades.producer.CheckoutBusinessFacade;
import com.sdd.plains.AddressPlain;
import com.sdd.plains.CartPlain;
import com.sdd.plains.CustomerPlain;
import com.sdd.plains.DeliveryPlain;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jms.JMSException;
import javax.naming.NamingException;

/**
 *
 * @author tpgalan
 */
@Stateless
public class CheckoutViewFacadeBean implements CheckoutViewFacade{

    @EJB
    OrderBusinessFacadeBean orderBusinessFacadeBean;
    @EJB
    OrderFactoryFacadeBean orderFactoryFacadeBean;
    @EJB
    CheckoutBusinessFacade checkoutBusinessFacade;
    @EJB
    DeliveryBusinessFacadeBean deliveryBusinessFacadeBean;
    
    @Override
    public CartPlain addCart(CartPlain cp, CustomerPlain customer, AddressPlain addressPlain) {
        return orderFactoryFacadeBean.createCartPlain(orderBusinessFacadeBean.addOrder(cp, customer, addressPlain));
    }

    @Override
    public DeliveryPlain getDelivery(AddressPlain ap, Long id, int ccnumber, int secnumber) {
        try {
            checkoutBusinessFacade.send(ap, id, ccnumber, secnumber);
            System.out.println("En getDelivery");
        } catch (NamingException ex) {
            Logger.getLogger(CheckoutViewFacadeBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JMSException ex) {
            Logger.getLogger(CheckoutViewFacadeBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        Delivery d = deliveryBusinessFacadeBean.getDelivery(1L);
        DeliveryPlain dplain = new DeliveryPlain();
        dplain.setWebUrl(d.getWebUrl());
        System.out.println(dplain);
        return dplain;
    }
    
}
